home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / sleipnir165.exe / {app} / developers / TypeLib / showlink / showlink.cpp next >
Text File  |  2004-07-12  |  2KB  |  78 lines

  1. // showlink.cpp
  2.  
  3. #include <windows.h>
  4.  
  5. #import <shdocvw.dll>  rename_namespace("SHDOCVW")   named_guids
  6. #import <mshtml.tlb>   rename_namespace("MSHTML")    named_guids
  7. #import "..\Sleipnir.tlb" rename_namespace ("Sleipnir") named_guids
  8.  
  9.  
  10. void Run(Sleipnir::IAPIPtr& pnir)
  11. {
  12.     MSHTML::IHTMLDocument2Ptr document;
  13.  
  14.     long id = pnir->GetDocumentID(pnir->ActiveIndex);
  15.     document = pnir->GetDocumentObject(id);
  16.  
  17.     if (document == 0) {
  18.         pnir->MessageBox("Document âIâuâWâFâNâgé≡ì∞ɼé┼é½é▄é╣é±");
  19.     } else {
  20.         MSHTML::IHTMLElementCollectionPtr links = document->links;
  21.         if (links) {
  22.             for (int i=0; i<links->length; i++) {
  23.                 MSHTML::IHTMLElementPtr elm = links->item(&_variant_t((long)i), &_variant_t((long)i));
  24.                 if (elm) {
  25.                     MSHTML::IHTMLAnchorElementPtr anchorElm = elm;
  26.  
  27.                     if (anchorElm) {
  28.                         BSTR href;
  29.                         anchorElm->get_href(&href);
  30.  
  31.                         elm->insertAdjacentHTML("AfterEnd", _bstr_t("<b><small>(") + href + ")</small></b>");
  32.                         anchorElm = 0;
  33.                     }
  34.                     elm = 0;
  35.                 }
  36.             }
  37.             links = 0;
  38.         }
  39.     }
  40.     pnir->Beep();
  41.     document = 0;
  42. }
  43.  
  44. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
  45. {
  46.     if (FAILED(CoInitialize(NULL))) {
  47.         MessageBox(NULL, "Failed \"CoInitialize\"", "Error", MB_OK|MB_ICONERROR);
  48.         return -1;
  49.     }
  50.  
  51.     Sleipnir::IAPIPtr ApiPointer;
  52.     
  53.     try {
  54.         HRESULT hr;
  55.         hr = ApiPointer.CreateInstance(Sleipnir::CLSID_API);
  56.         
  57.         if (FAILED(hr))
  58.             _com_issue_error(hr);
  59.     }
  60.     catch (_com_error& e) {
  61.         MessageBox(NULL, e.ErrorMessage(), "Error", MB_OK|MB_ICONERROR);
  62.         return -1;
  63.     }
  64.  
  65.     try {
  66.         Run(ApiPointer);
  67.     }
  68.     catch (_com_error& e) {
  69.         MessageBox(NULL, e.ErrorMessage(), "Error", MB_OK|MB_ICONERROR);
  70.         return -1;
  71.     }
  72.  
  73.     ApiPointer = 0;
  74.     CoUninitialize();
  75.  
  76.     return 0;
  77. }
  78.